package model.juliStaff.propo;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Date: Sep 5, 2009 Time: 8:25:53 PM
 *
 * @author Maria Julia Racca;
 */

public class AtomicProposition extends AbstractProposition {

    private char value;

    public AtomicProposition(char value, boolean isNot) {

        this.value = value;

        if (isNot) {
            this.negated = Operation.NOT;
        } else {
            this.negated = Operation.NON;
        }
    }

    // @Override
    public String toString() {

        StringBuffer sb = new StringBuffer();

        if (negated == Operation.NOT) {
            sb.append(negated.toString());
        }

        sb.append(value);

        return sb.toString();
    }

    public char getValue() {
        return value;
    }

    public void setValue(char value) {
        this.value = value;
    }

    // @Override
    public boolean equals(Object obj) {
        return compareTo((Proposition) obj) == 0;
    }

    // @Override
    public int compareTo(Proposition obj) {

        AtomicProposition p = (AtomicProposition) obj;

        boolean n = negated.equals(p.getNegated());
        boolean equals = equals(p);

        if (!equals) {
            return -1;
        } else if (n) {
            return 0;
        }
        return 1;

    }

    // @Override
    public boolean compare(Proposition obj) {

        if (obj == null || obj instanceof MolecularProposition) {
            return false;
        }

        AtomicProposition p = (AtomicProposition) obj;
        return value == p.getValue();

    }
}
